<template>
  <div class="my-home">
    <!-- 顶部搜索 -->
    <van-nav-bar class="nav-bar">
      <template #title>
        <div class="location" @click="$router.push('/city')">
          <span>{{ myCity.label }}</span>
          <i class="iconfont icon-arrow"></i>
        </div>
        <div class="form">
          <i slot="icon" class="iconfont icon-seach"></i>
          <span class="text">请输入小区或地址</span>
        </div>
      </template>
      <template #right>
        <i class="iconfont icon-map" @click="$router.push('/map')"></i>
      </template>
    </van-nav-bar>
    <!-- 轮播图 -->
    <van-swipe :autoplay="3000" class="swipes">
      <van-swipe-item v-for="image in images" :key="image.id">
        <img :src="imgBaseURL + image.imgSrc" />
      </van-swipe-item>
    </van-swipe>
    <!-- 选项卡 -->
    <function-options></function-options>
    <!-- 租房小组 -->
    <rent-group></rent-group>
  </div>
</template>

<script>
import { homeSwiperAPI } from '@/api'
import { mapState } from 'vuex'
import RentGroup from './components/RentGroup.vue'
import FunctionOptions from './components/FunctionOptions.vue'
export default {
  name: 'Home',
  components: { RentGroup, FunctionOptions },
  data() {
    return {
      images: [],
      imgBaseURL: 'http://liufusong.top:8080'
    }
  },
  computed: {
    ...mapState(['myCity'])
  },
  created() {
    this.homeSwiper()
  },
  methods: {
    // 获取轮播图
    async homeSwiper() {
      const data = await homeSwiperAPI()
      this.images = data.body
    }
  }
}
</script>

<style scoped lang="less">
// 搜索框
:deep(.nav-bar) {
  position: absolute;
  top: 25px;
  width: 100%;
  padding: 0 10px;
  z-index: 2;
  background-color: unset;
  .van-nav-bar__content {
    justify-content: space-between;
    align-items: center;
    height: 34px;
    .van-nav-bar__title {
      max-width: unset;
      margin: 0 10px;
      width: 310px;
      height: 34px;
      display: flex;
      align-items: center;
      border-radius: 3px;
      padding: 5px 5px 5px 8px;
      background-color: #fff;
      .location {
        width: 42px;
        font-size: 14px;
        color: #333;
        .icon-arrow {
          margin-left: 2px;
          font-size: 12px;
          color: #7f7f80;
        }
      }
      .form {
        border-left: 1px solid #e5e5e5;
        margin-left: 12px;
        .icon-seach {
          vertical-align: middle;
          padding: 0 2px 0 12px;
          color: #9c9fa1;
          font-size: 15px;
        }
        .text {
          padding-left: 4px;
          font-size: 13px;
          color: #9c9fa1;
        }
      }
    }
    .van-nav-bar__right {
      padding: 0;
      .icon-map {
        font-size: 25px;
        color: #fff;
      }
    }
  }
  &::after {
    content: '';
    border-bottom-width: 0;
  }
}
// 轮播图
:deep(.swipes) {
  height: 212px;
  img {
    width: 100%;
  }
  .van-swipe__indicators {
    bottom: 4px;
    .van-swipe__indicator {
      height: 8px;
      width: 8px;
      background-color: #ccc;
      margin: 0 3px;
    }
    .van-swipe__indicator--active {
      background-color: #888;
    }
  }
}
</style>
